#include <gmp.h>
#include <gmpxx.h>

//#define BITSTRENGTH 512
#define E_SEED			65537

// TAGS
#define TAG_INTEGER					0x02
#define TAG_BITSTRING				0x03
#define TAG_OCTETSTRING			0x04
#define TAG_NULL						0x05
#define TAG_OID							0x06
#define TAG_SEQUENCE				0x10
#define TAG_SET							0x11
#define TAG_PRINTSTRING			0x13
#define TAG_T61STRING				0x14
#define TAG_IA5STRING						0x16
#define TAG_UTCTIME							0x17

// CLASS
#define UNIVERSAL								0x00
#define APPLICATION							0x01
#define CONTEXTSPEC							0x10
#define PRIVATE									0x11

#define PRIMITIVE								0x20
#define CONSTRUCTED							0x00

// Identifiers
#define IDENT_BOOL							0x01
#define IDENT_INTEGER						0x02
#define IDENT_ENUM							0x02
#define	IDENT_REAL							0x02
#define IDENT_BITSTRING_PRIM		0x03
#define IDENT_BITSTRING_CONS		0x23
#define	IDENT_OCTET_PRIM				0x04
#define IDENT_OCTET_CONS				0x24
#define IDENT_NULL							0x05
#define IDENT_SEQ								0x30		
#define IDENT_SET								0x31
#define IDENT_OID								0x06

//length Octet
#define MULTLENOCTET						0x80

#define ALGOVERLEN							0x01
#define ALGOVER									0x00

static const char pubkeyheader[] = {0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 
																		0x48, 0x86, 0xf7,	0x0d, 0x01, 0x01, 
																		0x01, 0x05, 0x00};

class rsakeys
{
	public:
	mpz_t p,q,n,e,d;

	void generateKeys();
	bool convertPrivKeyFile();
	bool createPrivKey();
	bool createPubKey();
	void fillIntegerBuffer(uchar *buff, uint &buffindex, uchar *temp, uint count);
	void clearBignums();
	bool writePrivateKeyToFile(uchar *buff, uint bufflen);
	
};
